"""
This module responds for about dialog
"""

import pygtk
import gtk
import gobject
import webbrowser

from .. import exceptions
from .. import path
from .. import version

parent = None

gtk.about_dialog_set_url_hook(lambda dialog, link: webbrowser.open(link))

def initialize(parent_window):
    """
        Initialize module, parent_window must point to main application window
    """
    global parent

    if not parent is None:
        raise exceptions.InitializationError("Module already initialized!")
    
    parent = parent_window
    
def assert_initialized():
    if parent is None:
        raise exceptions.GuiException("Module 'about' is not initialized!")

def run_dialog():
    """
        Display about dialog
    """
    
    assert_initialized()
    xml = gtk.glade.XML(path.get_data_path("pybookshelf.glade"), root="about_dialog",
                        domain="pybookshelf")
    dialog = xml.get_widget("about_dialog")
    
    dialog.set_version(version.__version__)
    dialog.set_transient_for(parent)
    response = dialog.run()
    dialog.destroy()
    
    return response
    